package com.example.demo;

import com.tanx.cqrs.event.store.EventStoreRepository;
import com.tanx.cqrs.event.store.MongodbEventStoreRepositoryImpl;
import com.tanx.cqrs.eventsourcing.snapshot.MongoSnapshotBuildStrategyImpl;
import com.tanx.cqrs.eventsourcing.snapshot.MongoSnapshotRepositoryImpl;
import com.tanx.cqrs.eventsourcing.snapshot.SnapshotBuildStrategy;
import com.tanx.cqrs.eventsourcing.snapshot.SnapshotRepository;
import com.tanx.cqrs.saga.SagaStoreRepository;
import com.tanx.cqrs.saga.impl.MongoSagaStoreRepositoryImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    public EventStoreRepository storeRepository() {
        MongodbEventStoreRepositoryImpl mongodbEventStoreRepository = new MongodbEventStoreRepositoryImpl();
        mongodbEventStoreRepository.setCollectionName("EventStore");
        return mongodbEventStoreRepository;
    }

    @Bean
    public SnapshotBuildStrategy snapshotBuildStrategy() {
        MongoSnapshotBuildStrategyImpl strategy = new MongoSnapshotBuildStrategyImpl();
        strategy.setMaxEventCount(10);
        return strategy;
    }

    @Bean
    public SnapshotRepository snapshotRepository() {
        MongoSnapshotRepositoryImpl snapshotRepository = new MongoSnapshotRepositoryImpl();
        snapshotRepository.setCollectionName("Snapshot");
        return snapshotRepository;
    }

    @Bean
    public SagaStoreRepository sagaStoreRepository() {
        return new MongoSagaStoreRepositoryImpl("sagaStore");
    }
}
